/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.quickorm.entity;

import java.util.Date;
import java.util.List;

/**
 *
 * @author aaa
 */
public class SqlAndArgumentsData {

    private String sql;
    private List<Object> argumentList;
    private List<List<Object>> argumentListList;

    /**
     * @return the sql
     */
    public String getSql() {
        return sql;
    }

    /**
     * @return the argumentList
     */
    public List<Object> getArgumentList() {
        return argumentList;
    }

    /**
     * @param argumentList the argumentList to set
     */
    public void setArgumentList(List<Object> argumentList) {
        this.argumentList = argumentList;
    }

    /**
     * @return the argumentListList
     */
    public List<List<Object>> getArgumentListList() {
        return argumentListList;
    }

    /**
     * @param argumentListList the argumentListList to set
     */
    public void setArgumentListList(List<List<Object>> argumentListList) {
        this.argumentListList = argumentListList;
    }

    public SqlAndArgumentsData(String sql) {
        this.sql = sql;
    }

    @Override
    public String toString() {
        String finalSql = null;
        if (argumentList != null) {
            StringBuilder sb = new StringBuilder(this.getSql());
            for (Object argument : argumentList) {
                int index = sb.indexOf("?");
                if (index < 0) {
                    continue;
                }
                String argumentString = null;
                if (String.class.isInstance(argument)) {
                    argumentString = String.format("'%s'", argument);
                } else if (Date.class.isInstance(argument)) {
                    argumentString = String.format("'%s'", argument);
                } else {
                    argumentString = argument.toString();
                }
                sb.replace(index, index + 1, argumentString);
            }
            finalSql = sb.toString();
        } else if (argumentListList
                != null) {
        } else {
            finalSql = this.getSql();
        }

        return finalSql;
    }
}
